package com.answer.model.enums;

import lombok.AllArgsConstructor;

@AllArgsConstructor
public enum UserEnum {




    ADMIN("管理员",0),
    USER("用户",1)
    ;


    String text;
    Integer code;

    //通过code获取text
    public static String getTextByCode(Integer code) {
        for (UserEnum genderEnum: UserEnum.values()){
            if (genderEnum.code.equals(code)){
                return genderEnum.text;
            }
        }
        return "";
    }



    //通过text获取code
    public static Integer getCodeByText(String text) {
        for (UserEnum genderEnum: UserEnum.values()){
            if (genderEnum.text.equals(text)){
                return genderEnum.code;
            }
        }
        return -1;
    }

    /**
     * 判断该值是否在枚举中定义，定义了返回true，未定义返回false
     * @param code
     * @return
     */
    public static boolean isCode(Integer code){
        for (UserEnum genderEnum: UserEnum.values()){
            if (genderEnum.code.equals(code)){
                return true;
            }
        }
        return false;
    }

    public String getText() {
        return text;
    }


    public Integer getCode() {
        return code;
    }

}
